package com.views.warSoul {
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	import flash.geom.*;

	public class WarSoul extends Sprite {

		private var _mcTime:Timer;
		private var _soulNum:int = 0;
		private var _soulList:Array;
		private var _shansuoList:Array;

		public function WarSoul() {
			this._mcTime = new Timer(20);
			super();
			this._soulList = [];
			this._shansuoList = [];
			this._mcTime.addEventListener(TimerEvent.TIMER, this.mcTimeHandler);
		}

		public function getStartPoint(_arg1:Point):void {
			WarSoulData.StartPoint = _arg1;
		}

		public function getEndPoint(_arg1:Point):void {
			WarSoulData.EndPoint = _arg1;
		}

		public function getSoulTarget(_arg1:Class):void {
			WarSoulData.SoulTarget = _arg1;
		}

		public function lightTarget(_arg1:Class):void {
			WarSoulData.LightTarget = _arg1;
		}

		public function getSoulNum(_arg1:int):void {
			this._soulNum = _arg1;
		}

		public function mcPlay():void {
			this.renderSoul();
			this._mcTime.start();
		}

		private function renderSoul():void {
			var soul:* = null;
			var c:* = null;
			var soulMc:* = null;
			var angle:* = NaN;
			var ran:* = NaN;
			var startPoint:* = WarSoulData.StartPoint;
			var x1:* = (startPoint.x - 100);
			var y1:* = (startPoint.y - 100);
			var endPoint:* = WarSoulData.EndPoint;
			var i:* = 0;
			while (i < this._soulNum) {
				soul = new Soul();
				soul.lostTime((WarSoulData.mcLostTime * i));
				c = WarSoulData.SoulTarget;
				soulMc = (new (c)() as MovieClip);
				soul.target = soulMc;
				soul.x = (x1 + Math.floor((Math.random() * 200)));
				soul.y = (y1 + Math.floor((Math.random() * 200)));
				angle = Moving.mcAngle(startPoint, endPoint);
				soul.angle = (angle + Math.floor((Math.random() * 100)));
				ran = (0.2 + (Math.random() * 0.5));
				soul.scaleX = ran;
				soul.scaleY = ran;
				soul.DefuleScale = ran;
				soul.onEnd = function():void {
					addShanSuo();
				};
				this._soulList.push(soul);
				this.addChild(soul);
				soul.addChild(soulMc);
				soul.mcPlay();
				i = (i + 1);
			}
			;
		}

		private function addShanSuo():void {
		}

		private function ssState():void {
			var _local3:Object;
			var _local4:MovieClip;
			var _local1:int = this._shansuoList.length;
			var _local2:int = (_local1 - 1);
			while (_local2 >= 0) {
				_local3 = this._shansuoList[_local2];
				if (_local3.time <= 0) {
					_local4 = this._shansuoList[_local2].mc;
					_local4.stop();
					_local4.parent.removeChild(_local4);
					_local4 = null;
					this._shansuoList.splice(_local2, 1);
				} else {
					_local3.time--;
				}
				;
				_local2--;
			}
			;
		}

		private function ssClear():void {
			var _local3:Object;
			var _local4:MovieClip;
			var _local1:int = this._shansuoList.length;
			var _local2:int = (_local1 - 1);
			while (_local2 >= 0) {
				_local3 = this._shansuoList[_local2];
				_local4 = this._shansuoList[_local2].mc;
				_local4.stop();
				_local4.parent.removeChild(_local4);
				_local4 = null;
				_local2--;
			}
			;
			this._shansuoList = null;
		}

		private function soulPlay():void {
			var _local3:Soul;
			var _local1:int = this._soulList.length;
			var _local2:int;
			while (_local2 < _local1) {
				_local3 = (this._soulList[_local2] as Soul);
				_local3.move();
				_local2++;
			}
			;
		}

		private function mcTimeHandler(_arg1:TimerEvent):void {
			this.soulPlay();
			this.mcState();
			this.ssState();
		}

		private function mcState():void {
			var _local3:Soul;
			var _local1:int = this._soulList.length;
			var _local2:int = (_local1 - 1);
			while (_local2 >= 0) {
				_local3 = (this._soulList[_local2] as Soul);
				if (_local3.isMcEnd) {
					_local3.target.stop();
					_local3.removeChild(_local3.target);
					_local3.target = null;
					_local3.parent.removeChild(_local3);
					_local3 = null;
					this._soulList.splice(_local2, 1);
				}
				;
				_local2--;
			}
			;
		}

		private function mcClear():void {
			var _local3:Soul;
			var _local1:int = this._soulList.length;
			var _local2:int = (_local1 - 1);
			while (_local2 >= 0) {
				_local3 = (this._soulList[_local2] as Soul);
				_local3.target.stop();
				_local3.removeChild(_local3.target);
				_local3.target = null;
				_local3.parent.removeChild(_local3);
				_local3 = null;
				_local2--;
			}
			;
		}

		public function clear():void {
			this._mcTime.stop();
			this.ssClear();
			this.mcClear();
			this._mcTime.addEventListener(TimerEvent.TIMER, this.mcTimeHandler);
			this._mcTime = null;
		}

	}
}
